package com.rerun.common.util;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.apache.commons.lang3.time.FastDateFormat;

import java.io.IOException;
import java.util.Date;

/**
 * The type Json date format.
 *
 * @author dax.
 * @version v1.0
 * @since 2017 /9/30 14:38
 */
public class JsonDateFormat extends JsonSerializer<Date> {
    private FastDateFormat fastDateFormat=FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");
    @Override
    public void serialize(Date date, JsonGenerator gen, SerializerProvider provider)  throws IOException {
        String value = fastDateFormat.format(date);
        gen.writeString(value);
    }
}
